package com.itheima.FileTest;

import java.io.*;
import java.util.ArrayList;

public class Test3 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {

        ArrayList<Student> list = new ArrayList<>();
        Student s1 = new Student("杜子腾",16);
        Student s2 = new Student("张三",23);
        Student s3 = new Student("李四",24);

        list.add(s1);
        list.add(s2);
        list.add(s3);

        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("c.txt"));
        oos.writeObject(list);
        oos.close();

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("c.txt"));
        ArrayList<Student> list2 = (ArrayList<Student>) ois.readObject();

        for (Student student : list2) {
            System.out.println(student);
        }


//        while(true){
//            try {
//                Object o = ois.readObject();
//                System.out.println(o);
//            } catch (EOFException | ClassNotFoundException e) {
//                break;
//            }
//        }
        ois.close();
    }
}
